﻿var isBack = true;
function goBack() {
    if (isBack) {
        location.href = "/ContentType/TypeList";
    }
    else {
        location.href = "/ContentType/TypeAdd";
    }
}
function chengeBack(op) {
    isBack = op;
}
function SubData() {
    var postData = {
        ModalityID: $("#ModalitySelect").val(),
        ProductID: $("#ProductSelect").val(),
        ContentType: $("#CType").val().trim(),
        IsActive: $("#PIsActive").val()
    };
    $.ajax({
        type: 'post',
        url: '/ContentType/AddInfo',
        data: postData,
        success: function (data) {
            if (data == "suc") {
                //关闭层，刷新表单
                goBack();
            }
            else if (data == "repeat") {
                $.alert({
                    title: '系统提示',
                    content: '重复数据无法添加！',
                    confirm: function () {
                    }
                });
            }
            else {
                $.alert({
                    title: '系统提示',
                    content: '操作失败！',
                    confirm: function () {
                    }
                });
            }
        },
        error: function () {
            $.alert({
                title: '系统提示',
                content: '操作失败！',
                confirm: function () {
                }
            });
        }
    });
}
$(function () {
    $("#rightResources").addClass("active");
    $('#TypeAddForm')
    .bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            ModalitySelect: {
                message: 'The Modality is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Modality is required and can\'t be empty'
                    }
                }
            },
            ProductSelect: {
                message: 'The Product is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Product is required and can\'t be empty'
                    }
                }
            }
            ,
            CType: {
                message: 'The Content Type is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Content Type is required and can\'t be empty'
                    }
                }
            }
        }
    })
    .on('success.form.bv', function (e) {
        e.preventDefault();
        SubData();
    });
});